﻿using JESAI.Application.Abstractions.Dtos;
using JESAI.Application.Abstractions.Sys;
using JESAI.Application.Abstractions.Sys.Dtos;
using JESAI.Application.Abstractions.Sys.Querys;
using JESAI.Application.Service.Sys;
using JESAI.AutoMapper.ObjectMapping;
using JESAI.Framework.Filters;
using JESAI.Platform.WebApi.Vos.Sys;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace JESAI.Platform.WebApi.Controllers.Sys
{
    [ApiController]
    [Route("api/v1/[controller]")]
    [Authorize("permission")]
    [IgnoreResultHandlerAttribute]
    public class OnlineController : ControllerBase
    {
        private readonly IOnlineService _onlineService;
        public OnlineController(IOnlineService onlineService)
        {
            _onlineService = onlineService;
        }

        [HttpGet("GetPageList")]
        public async Task<BasePageOutput<List<OnlineInfoResponse>>> GetPageList([FromQuery] OnlineInfoPageQuery onlineInfoPageQuery)
        {
            var formPageList = await _onlineService.GetPageList(onlineInfoPageQuery);
            return formPageList.MapTo<BasePageOutput<List<OnlineInfoResponse>>>();
        }

        [HttpGet("GetOnlineFieldsByOnlineInfoId")]
        public async Task<BaseOutput<List<OnlineFieldResponse>>> GetOnlineFieldsByOnlineInfoId(string onlineInfoId)
        {
            var onlineFieldList = await _onlineService.GetOnlineFieldsByOnlineInfoId(onlineInfoId);
            return new BaseOutput<List<OnlineFieldResponse>>() { Data = onlineFieldList.MapTo<List<OnlineFieldResponse>>() };
        }


        [HttpPost("SetOnlineInfo")]
        public async Task<BaseOutput> SetOnlineInfo([FromBody] OnlineInfoInput input)
        {
            await _onlineService.SetOnlineInfo(input);
            return new BaseOutput();
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpGet("DeleteOnlineInfos")]
        public async Task<BaseOutput> DeleteOnlineInfos(string[] ids)
        {
            await _onlineService.DeleteOnlineInfos(ids);
            return new BaseOutput { };
        }

        /// <summary>
        /// 单个删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("DeleteOnlineInfo")]
        public async Task<BaseOutput> DeleteOnlineInfo(string id)
        {
            await _onlineService.DeleteOnlineInfo(id);
            return new BaseOutput { };
        }

        /// <summary>
        /// 单个删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("GetOnlineInfoByFormCode")]
        public async Task<BaseOutput<OnlineInfoResponse>> GetOnlineInfoByFormCode(string formCode)
        {
            var onlineInfo = await _onlineService.GetOnlineInfoByFormCode(formCode);
            return new BaseOutput<OnlineInfoResponse> { Data = onlineInfo.MapTo<OnlineInfoResponse>() };
        }
    }
}
